package org.example.helloworld.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.helloworld.entity.ElcPri;
import org.example.helloworld.entity.WaPrice;
import org.example.helloworld.service.IElcPriService;
import org.example.helloworld.service.IWaPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 水费价格 前端控制器
 * </p>
 *
 * @author cwf
 * @since 2024-07-10
 */
@RestController
@RequestMapping("/waPrice")
public class WaPriceController {
    @Autowired
    private IWaPriceService IWaPriceService;

//    @GetMapping
//    public List<ElcPri> getAllRates() {
//        return IElcPriService.list();
//    }

    @GetMapping("/{id}")
    public WaPrice getRateById(@PathVariable String id) {
        return IWaPriceService.getById(id);
    }

    @PostMapping("/add")
    public boolean addRate(@RequestBody WaPrice rate) {
        return IWaPriceService.save(rate);
    }

    @PutMapping("/update")
    public boolean updateRate(@RequestBody WaPrice rate) {
        return IWaPriceService.updateById(rate);
    }

    @DeleteMapping("/{id}")
    public boolean deleteRate(@PathVariable String id) {
        return IWaPriceService.removeById(id);
    }


    @GetMapping
    public IPage<WaPrice> getAllRates(
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "5") int size,
            @RequestParam(value = "search", required = false) String search) {
        Page<WaPrice> WaPricePage = new Page<>(page, size);
        IPage<WaPrice> resultPage = IWaPriceService.getWaPriceList(WaPricePage, search);
        return resultPage;
    }
}
